package com.yunhe.transfer.config;

import com.yunhe.transfer.websocket.HeartbeatWSHandler;
import com.yunhe.transfer.websocket.RealtimeMeasBatchSaveHandler;
import com.yunhe.transfer.websocket.RecollectHandler;
import com.yunhe.transfer.websocket.RunStrategyWebsocketHandler;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.socket.WebSocketHandler;
import org.springframework.web.socket.config.annotation.EnableWebSocket;
import org.springframework.web.socket.config.annotation.WebSocketConfigurer;
import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry;

/**
 * WebSocket配置类
 */
@Configuration
@EnableWebSocket
public class WebSocketConfig implements WebSocketConfigurer {

    @Override
    public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
        registry.addHandler(realtimeMeasBatchSave(), "/measurements/realtime/socket").setAllowedOrigins("*");
        registry.addHandler(runStrategy(), "/runStrategy/socket").setAllowedOrigins("*");
        registry.addHandler(recollect(), "/measurements/recollect/socket").setAllowedOrigins("*");
        registry.addHandler(heartbeat(), "/heartbeat/socket").setAllowedOrigins("*");
    }

    @Bean
    public WebSocketHandler realtimeMeasBatchSave() {
        return new RealtimeMeasBatchSaveHandler();
    }

    @Bean
    public WebSocketHandler runStrategy() {
        return new RunStrategyWebsocketHandler();
    }

    @Bean
    public WebSocketHandler recollect() { return new RecollectHandler();}

    @Bean
    public WebSocketHandler heartbeat() { return new HeartbeatWSHandler();}

}